const state = {
	msg: '测试数据',

	songListNow: [],
}

const mutations = {
	// 添加正在播放的歌曲
	addSongListNow(state, item) {
		state.songListNow.push(item)
		console.log('添加执行');
		uni.setStorageSync('songListNow', JSON.stringify(state.songListNow))
	},
	// 删除 正在播放的歌曲
	deleteAllSong(state, type) {
		let index = 0
		// type 不传 则是删除所有，传则是 歌曲的 id 删除单个
		if (!type) {
			state.songListNow = []

		} else {
			index = state.songListNow.findIndex((item, index) => item.id == type)
			state.songListNow.splice(index, 1)
		}
		console.log('删除后的播放列表', state.songListNow);
		console.log('删除的索引', index, state.songListNow.length);
		if (state.songListNow.length == index) {
			console.log('相等了', state.songListNow[0]);
			let obj = state.songListNow[0]
			return obj
		} else {
			return state.songListNow[index]
		}

	}
}

const actions = {}

const getters = {
	// text:state => state.text
}

export default {
	namespaced: true,
	state,
	mutations,
	actions,
	getters
}
